package com.example.websocketdemo.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class EnvironmentalMeteorologicalService {

    public void e(String message) throws IOException {
        JSONObject transition = JSON.parseObject(message);
        String value = (String) transition.get("环保气象区域名称");

        JSONObject jsonObject = new JSONObject();
        JSONObject xinxi = new JSONObject();
        JSONObject xinxi1 = new JSONObject();
        JSONObject xinxi2 = new JSONObject();
        JSONObject xinxi3 = new JSONObject();
        JSONObject xinxi4 = new JSONObject();

        JSONArray Array = new JSONArray();
        jsonObject.put("instruction","huanbaoqixiang");
        if (value.equals("消防泵房")){
            xinxi.put("id","消防泵房");
            xinxi.put("所属区域名称","消防泵房");
            xinxi.put("设备名称","消防水池");
            xinxi.put("指标名称","LT8301B消防水池液位");
            xinxi.put("实时●数值","1.88");
            xinxi.put("单位","m");
            xinxi.put("低低报","-");
            xinxi.put("低报","-");
            xinxi.put("高报","-");
            xinxi.put("高高报","-");
            xinxi.put("量程下限","-");
            xinxi.put("量程上限","-");
            xinxi.put("位号","SCADA_A_LT8301B");
            xinxi.put("issue","false");

            xinxi4.put("id","消防泵房");
            xinxi4.put("所属区域名称","消防泵房");
            xinxi4.put("设备名称","消防水池");
            xinxi4.put("指标名称","LT8301A消防水池液位");
            xinxi4.put("实时●数值","2.20");
            xinxi4.put("单位","m");
            xinxi4.put("低低报","-");
            xinxi4.put("低报","-");
            xinxi4.put("高报","-");
            xinxi4.put("高高报","-");
            xinxi4.put("量程下限","-");
            xinxi4.put("量程上限","-");
            xinxi4.put("位号","SCADA_A_LT8301A");
            xinxi4.put("issue","true");
            Array.add(xinxi);
            Array.add(xinxi4);
        }else if (value.equals("泡沫站")){
            xinxi1.put("id","泡沫站");
            xinxi1.put("所属区域名称","泡沫站");
            xinxi1.put("设备名称","生活水池");
            xinxi1.put("指标名称","LT8501生活水池液位");
            xinxi1.put("实时●数值","2.15");
            xinxi1.put("单位","m");
            xinxi1.put("低低报","-");
            xinxi1.put("低报","-");
            xinxi1.put("高报","2");
            xinxi1.put("高高报","-");
            xinxi1.put("量程下限","0");
            xinxi1.put("量程上限","10");
            xinxi1.put("位号","SCADA_A_LT8501");
            xinxi1.put("issue","false");
            Array.add(xinxi1);
        }else if (value.equals("应急水池站")){
            xinxi2.put("id","应急水池站");
            xinxi2.put("所属区域名称","应急水池站");
            xinxi2.put("设备名称","雨水收集池");
            xinxi2.put("指标名称","LT8401雨水池液位");
            xinxi2.put("实时●数值","2.09");
            xinxi2.put("单位","m");
            xinxi2.put("低低报","-");
            xinxi2.put("低报","-");
            xinxi2.put("高报","2");
            xinxi2.put("高高报","-");
            xinxi2.put("量程下限","0");
            xinxi2.put("量程上限","10");
            xinxi2.put("位号","SCADA_A_LT8401");
            xinxi2.put("issue","false");
            Array.add(xinxi2);
        }else if (value.equals("HDPE装置")){
            xinxi3.put("id","HDPE装置");
            xinxi3.put("所属区域名称","HDPE装置");
            xinxi3.put("设备名称","油气回收装置");
            xinxi3.put("指标名称","LT300SC吸收塔液位");
            xinxi3.put("实时●数值","4.13");
            xinxi3.put("单位","%");
            xinxi3.put("低低报","-");
            xinxi3.put("低报","-");
            xinxi3.put("高报","-");
            xinxi3.put("高高报","-");
            xinxi3.put("量程下限","0");
            xinxi3.put("量程上限","100");
            xinxi3.put("位号","YQHS_A_LT300SC");
            xinxi3.put("issue","true");
            Array.add(xinxi3);
        }
        jsonObject.put("array",Array);
        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
    }
}
